<div class="content">
    <form class="form-horizontal" name="courseForm" ng-submit="vm.submitForm(courseForm.$valid)" novalidate>
        <div class="ibox">
            <div class="ibox-title">
                <h5>科目信息</h5>
            </div>
            <div class="ibox-content">
                <div class="form-group" ng-show="!$state.params.type">
                    <label class="col-lg-3 control-label">科目名称</label>
                    <div class="col-lg-3">
                        <input type="text" name="courseName" class="form-control" placeholder="请输入科目名称" ng-model="vm.course.course_name" required>
                    </div>
                </div>
                <div class="form-group" ng-show="!$state.params.type">
                    <label class="col-lg-3 control-label">参赛人数</label>
                    <div class="col-lg-3">
                        <input type="number" name="courseNum" class="form-control" placeholder="请输入参赛人数" ng-model="vm.course.course_num" required>
                    </div>
                </div>
                
                <div class="form-group" ng-show="!$state.params.type">
                    <label class="col-lg-3 control-label">赛道类型</label>
                    <div class="col-lg-3">
                        <label class="radio" ng-repeat="item in vm.track_types">
                            <input icheck type="radio" name="courseTrackType" value="{{item.value}}" ng-model="vm.course.course_track_type" ng-change="vm.changeFn(vm.course.course_track_type)" required> {{item.name}}
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-3 control-label">发枪时间</label>
                    <div class="col-lg-9">
                        <div class="row">
                            <div class="col-xs-12 col-sm-4 col-md-4 col-lg-4 margin-bottom-20">
                                <div class="input-group date">
                                    <input name="startTime" type="text" size="10" class="form-control" ng-model="vm.course.course_start_time" data-date-format="yyyy-MM-dd" data-autoclose="1" placeholder="年-月-日" bs-datepicker required>
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                </div>
                            </div>
                            <div class="col-xs-12 col-sm-4 col-md-4 col-lg-4 margin-bottom-20">
                                <div class="input-group date">
                                    <input name="startTime" type="text" size="10" class="form-control" ng-model="vm.course.course_start_time" data-time-format="HH:mm:ss" data-autoclose="1" placeholder="时:分:秒" bs-timepicker required>
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-xs-12 col-sm-4 col-md-4 col-lg-4 margin-bottom-20" ng-if="vm.recalc">
                                <label class="checkbox data-tip-top" data-tip="如果赛事已开始，修改发枪时间会导致现有成绩不准确，如需重新计算成绩，请勾选此选项。">
                                    <input icheck type="checkbox" name="formatRecalc" ng-model="vm.course.recalc"> 重新计算成绩 <span class="glyphicon glyphicon-question-sign"></span>
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group" ng-if="vm.course.course_track_type=='oneway'">
                    <label class="col-lg-3 control-label">最晚出发时间</label>
                    <div class="col-lg-9">
                        <div class="row">
                            <div class="col-xs-12 col-sm-4 col-md-4 col-lg-4 margin-bottom-20">
                                <div class="input-group date">
                                    <input name="startTime" type="text" size="10" class="form-control" ng-model="vm.course.course_end_time" data-date-format="yyyy-MM-dd" data-autoclose="1" placeholder="年-月-日" bs-datepicker required>
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                </div>
                            </div>
                            <div class="col-xs-12 col-sm-4 col-md-4 col-lg-4 margin-bottom-20">
                                <div class="input-group date">
                                    <input name="startTime" type="text" size="10" class="form-control" ng-model="vm.course.course_end_time" data-time-format="HH:mm:ss" data-autoclose="1" placeholder="时:分:秒" bs-timepicker required>
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group" ng-show="!$state.params.type">
                    <label class="col-lg-3 control-label">关门时间</label>
                    <div class="col-lg-9">
                        <div class="row">
                            <div class="col-xs-12 col-sm-4 col-md-4 col-lg-4 margin-bottom-20">
                                <div class="input-group date">
                                    <input name="startTime" type="text" size="10" class="form-control" ng-model="vm.course.course_close_time" data-date-format="yyyy-MM-dd" data-autoclose="1" placeholder="年-月-日" bs-datepicker>
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                </div>
                            </div>
                            <div class="col-xs-12 col-sm-4 col-md-4 col-lg-4 margin-bottom-20">
                                <div class="input-group date">
                                    <input name="startTime" type="text" size="10" class="form-control" ng-model="vm.course.course_close_time" data-time-format="HH:mm:ss" data-autoclose="1" placeholder="时:分:秒" bs-timepicker>
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
                <div class="form-group" ng-show="!$state.params.type" ng-if="vm.course.course_track_type=='circle'">
                    <label class="col-lg-3 control-label">比赛类型</label>
                    <div class="col-lg-6">
                        <label class="radio">
                            <input icheck type="radio" name="raceType" value="0" ng-model="vm.course.course_race_type"> 定时
                        </label>
                        <label class="radio">
                            <input icheck type="radio" name="raceType" value="1" ng-model="vm.course.course_race_type"> 定距
                        </label>
                    </div>
                </div>
                <div class="form-group" ng-show="!$state.params.type" ng-if="vm.course.course_track_type=='circle'&&vm.course.course_race_type==0">
                    <label class="col-lg-3 control-label">比赛时长</label>
                    <div class="col-lg-3">
                        <input type="text" name="courseTiming" class="form-control" placeholder="单位时" ng-model="vm.course.course_timing" required>
                    </div>
                </div>
                <div class="form-group" ng-show="!$state.params.type" ng-if="vm.course.course_track_type=='circle'&&vm.course.course_race_type==1">
                    <label class="col-lg-3 control-label">圈数</label>
                    <div class="col-lg-3">
                        <input type="text" name="courseDistance" class="form-control" placeholder="圈数" ng-model="vm.course.course_distance" required>
                    </div>
                </div>
                <div class="form-group" ng-show="!$state.params.type" ng-if="vm.course.course_track_type=='retrace'">
                    <label class="col-lg-3 control-label">折返圈数</label>
                    <div class="col-lg-3">
                        <input type="text" name="courseDistance" class="form-control" placeholder="折返圈数" ng-model="vm.course.course_distance" required>
                    </div>
                </div>
                <div class="form-group" ng-show="!$state.params.type" ng-if="vm.course.course_track_type=='circle'||vm.course.course_track_type=='retrace'">
                    <label class="col-lg-3 control-label">单圈时间</label>
                    <div class="col-lg-3">
                        <input type="text" name="courseLapTime" class="form-control" placeholder="单圈时间/单位秒" ng-model="vm.course.lap_time" required>
                    </div>
                </div>
                <div class="form-group" ng-show="!$state.params.type">
                    <label class="col-lg-3 control-label">赛制类型</label>
                    <div class="col-lg-6">
                        <label class="radio">
                            <input icheck type="radio" name="formatType" value="1" ng-model="vm.course.format_type" required> 个人赛
                        </label>
                        <label class="radio">
                            <input icheck type="radio" name="formatType" value="8" ng-model="vm.course.format_type" required> 团体赛
                        </label>
                    </div>
                </div>

                <div class="form-group" ng-show="!$state.params.type">
                    <label class="col-lg-3 control-label">计时类型</label>
                    <div class="col-lg-6">
                        <label class="radio">
                            <input icheck type="radio" name="timing" value="0" ng-model="vm.course.timing" required> 枪声计时
                        </label>
                        <label class="radio">
                            <input icheck type="radio" name="timing" value="1" ng-model="vm.course.timing" required> 净计时 (含枪声计时)
                        </label>
                    </div>
                </div>
                <div class="form-group" ng-show="!$state.params.type">
                    <label class="col-lg-3 control-label">用于计时的打卡点排序</label>
                    <div class="col-lg-9">
                        <p class="help-block text-danger" ng-if="vm.listGroups.length>0">提示：<i class="fa fa-flag"></i>表示赛道起点，净计时将第一个计时点设为起点。</p>
                        <!-- 存在计时点 -->
                        <div class="margin-top-10" ng-if="vm.message.length>0">
                            <ul class="cp-list border">
                                <li>
                                    <label>
                                        <div class="row">
                                            <div ng-class="{true: 'col-xs-3', false: 'col-xs-4'}[vm.course.course_track_type=='custom']">打卡点编号</div>
                                            <div ng-class="{true: 'col-xs-3', false: 'col-xs-4'}[vm.course.course_track_type=='custom']">打卡点名称</div>
                                            <!-- <div ng-class="{true: 'col-xs-2', false: 'col-xs-3'}[vm.course.course_track_type=='custom']">打卡点类型</div> -->
                                            <div class="col-xs-3" ng-show="vm.course.course_track_type=='custom'">计时点间隔时间（据起点时间）</div>
                                            <div ng-class="{true: 'col-xs-3', false: 'col-xs-4'}[vm.course.course_track_type=='custom']">操作</div>
                                        </div>
                                    </label>
                                </li>
                            </ul>
                            <ul ng-sortable="sortableConfig" class="cp-list border">
                                <li ng-repeat="(index, cp) in vm.listGroups track by $index">
                                    <i class="fa fa-flag" ng-if="$first && vm.course.timing == 1" ></i>
                                    <label>
                                        <div class="row">
                                            <div ng-class="{true: 'col-xs-3', false: 'col-xs-4'}[vm.course.course_track_type=='custom']">{{cp.cp_index}}</div>
                                            <div ng-class="{true: 'col-xs-3', false: 'col-xs-4'}[vm.course.course_track_type=='custom']">{{cp.cp_name}}</div>
                                            <!-- <div ng-class="{true: 'col-xs-2', false: 'col-xs-3'}[vm.course.course_track_type=='custom']">
                                                <select name="cpType" class="form-control" ng-disabled="{{index==0}}">  
                                                    <option value="{{item.type}}" ng-repeat="(key, item) in vm.cp_type_list" ng-selected="{{index==0&&item.type=='start'}}">{{item.name}}</option>
                                                </select>
                                            </div> -->
                                            <div class="col-xs-3" ng-show="vm.course.course_track_type=='custom'">
                                                <input type="number" class="form-control laptime" placeholder="单位（秒）">
                                            </div>
                                            <div ng-class="{true: 'col-xs-3', false: 'col-xs-4'}[vm.course.course_track_type=='custom']">
                                                <button type="button" class="btn btn-white btn-sm" ng-click="upRecord(vm.listGroups, $index)" ng-disabled="$index==0">
                                                    <label class="checkbox data-tip-top" data-tip="调整计时点排序">
                                                        <i class="fa fa-long-arrow-up"></i>
                                                    </label>
                                                </button>
                                                <button type="button" class="btn btn-white btn-sm" ng-click="downRecord(vm.listGroups, $index)" ng-disabled="$index==vm.listGroups.length-1">
                                                    <label class="checkbox data-tip-top" data-tip="调整计时点排序">
                                                        <i class="fa fa-long-arrow-down"></i>
                                                    </label>
                                                </button>
                                                <button type="button" class="btn btn-white btn-sm" ng-click="deleteItem(vm.listGroups, $index)">
                                                    <label class="checkbox data-tip-top" data-tip="解除绑定">
                                                        <i class="fa fa-trash-o"></i>
                                                    </label>
                                                </button>
                                            </div>
                                        </div>
                                    </label>
                                </li>
                            </ul>
                            <ul class="cp-list border margin-bottom-20">
                                <li>
                                    <label>
                                        <div class="row">
                                            <div ng-class="{true: 'col-xs-3', false: 'col-xs-4'}[vm.course.course_track_type=='custom']">--</div>
                                            <div ng-class="{true: 'col-xs-3', false: 'col-xs-4'}[vm.course.course_track_type=='custom']">--</div>
                                            <!-- <div ng-class="{true: 'col-xs-2', false: 'col-xs-3'}[vm.course.course_track_type=='custom']">--</div> -->
                                            <div class="col-xs-3" ng-show="vm.course.course_track_type=='custom'">--</div>
                                            <div ng-class="{true: 'col-xs-3', false: 'col-xs-4'}[vm.course.course_track_type=='custom']">
                                                <button type="button" class="btn btn-sm btn-primary" ng-click="vm.importCp()" ng-disabled="vm.listGroups.length == vm.message.length&&vm.course.course_track_type!='retrace'&&vm.course.course_track_type!='custom'">导入</button>
                                            </div>
                                        </div>
                                    </label>
                                </li>
                            </ul>
                        </div>
                        <!-- 不存在计时点 -->
                        <div class="margin-top-10" ng-if="vm.message.length==0">
                            <p class="help-block text-danger">暂无打卡点。<a ui-sref="dashboard.race.cp" style="text-decoration: underline;">点击这里</a> 新增一个打卡点。</p>
                        </div>
                        
                    </div>
                </div>
                <div class="form-group" ng-show="!$state.params.type">
                    <div class="col-lg-offset-3 col-lg-6">
                        <button type="button" class="btn btn-sm btn-default" ui-sref="dashboard.race.index"><i class="fa fa-times"></i>取消</button>
                        <button type="submit" class="btn btn-sm btn-primary"><i class="fa fa-save"></i>保存</button>
                        <button type="button" class="btn btn-sm btn-danger" ng-click="vm.deleteItems($state.params.course_id)" ng-if="vm.$state.params.course_id"><i class="fa fa-trash-o"></i>删除</button>
                    </div>
                </div>
                <div class="form-group" ng-show="$state.params.type=='gun_time'">
                    <div class="col-lg-offset-3 col-lg-6">
                        <button type="button" class="btn btn-sm btn-default" ui-sref="dashboard.race.guntime"><i class="fa fa-times"></i>取消</button>
                        <button type="submit" class="btn btn-sm btn-primary"><i class="fa fa-save"></i>保存</button>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
